package com.niit.MostPopularMovieDecadeStart1980;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class MPMDSBean implements WritableComparable<MPMDSBean> {
    private String rate;
    private String rank;
    private String types;
    private String regions;
    private String title;
    private String release_data;
    private String actor_count;
    private String vote_count;
    private String score;
    private String actors;

    //2  反序列化时，需要反射调用空参构造函数
    public MPMDSBean() {
    }

    public MPMDSBean(String rate, String rank, String types, String regions, String title, String release_data, String actor_count, String vote_count, String score, String actors) {
        this.rate = rate;
        this.rank = rank;
        this.types = types;
        this.regions = regions;
        this.title = title;
        this.release_data = release_data;
        this.actor_count = actor_count;
        this.vote_count = vote_count;
        this.score = score;
        this.actors = actors;
    }

    //3  序列化方法
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(rate);
        dataOutput.writeUTF(rank);
        dataOutput.writeUTF(types);
        dataOutput.writeUTF(regions);
        dataOutput.writeUTF(title);
        dataOutput.writeUTF(release_data);
        dataOutput.writeUTF(actor_count);
        dataOutput.writeUTF(vote_count);
        dataOutput.writeUTF(score);
        dataOutput.writeUTF(actors);

    }

    //4 反序列化方法
    //5 反序列化方法读顺序必须和写序列化方法的写顺序必须一致
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        rate=dataInput.readUTF();
        rank=dataInput.readUTF();
        types=dataInput.readUTF();
        regions=dataInput.readUTF();
        title=dataInput.readUTF();
        release_data=dataInput.readUTF();
        actor_count=dataInput.readUTF();
        vote_count=dataInput.readUTF();
        score=dataInput.readUTF();
        actors=dataInput.readUTF();

    }

    // 6 编写toString方法，方便后续打印到文本
    @Override
    public String toString() {
        return rate + "\t" + rank + "\t" + types + "\t" + regions + "\t" + title + "\t" + release_data + "\t"
                + actor_count + "\t" + vote_count + "\t" + score + "\t" + actors + "\t";
    }


    public String getRate() {
        return rate;
    }

    public void setRate(String rate) {
        this.rate = rate;
    }

    public String getRank() {
        return rank;
    }

    public void setRank(String rank) {
        this.rank = rank;
    }

    public String getTypes() {
        return types;
    }

    public void setTypes(String types) {
        this.types = types;
    }

    public String getRegions() {
        return regions;
    }

    public void setRegions(String regions) {
        this.regions = regions;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getRelease_data() {
        return release_data;
    }

    public void setRelease_data(String release_data) {
        this.release_data = release_data;
    }

    public String getActor_count() {
        return actor_count;
    }

    public void setActor_count(String actor_count) {
        this.actor_count = actor_count;
    }

    public String getVote_count() {
        return vote_count;
    }

    public void setVote_count(String vote_count) {
        this.vote_count = vote_count;
    }

    public String getScore() {
        return score;
    }

    public void setScore(String score) {
        this.score = score;
    }

    public String getActors() {
        return actors;
    }

    public void setActors(String actors) {
        this.actors = actors;
    }

    public void set(String rate, String rank, String types, String regions, String title, String release_data, String actor_count, String vote_count, String score, String actors) {
        this.rate = rate;
        this.rank = rank;
        this.types = types;
        this.regions = regions;
        this.title = title;
        this.release_data = release_data;
        this.actor_count = actor_count;
        this.vote_count = vote_count;
        this.score = score;
        this.actors = actors;
    }

    @Override
    public int compareTo(MPMDSBean o) {
        int result;

        if (rate.compareTo(o.getRate())>0) {
            result = -1;
        } else if (rate.compareTo(o.getRate())<0) {
            result = 1;
        } else {
            result = 0;
        }
        return result;
    }


}
